<%@ page language="java" import="java.io.*" pageEncoding="UTF-8"%><% // 注意：这里的尖括号和百分号不要单独放在一行！否则会出现OutputStream冲突的错误！！！
    String path = "";
    String postfix = "";
    if (request.getParameter("path") != null) {
        path = request.getParameter("path");
    }
    
   	postfix = path.substring(postfix.lastIndexOf(".") + 1, path.length());
   	if (postfix.equalsIgnoreCase("jpg"))
    	response.setContentType("image/jpeg");
    else if (postfix.equalsIgnoreCase("png"))
    	response.setContentType("image/png");
    else if (postfix.equalsIgnoreCase("gif"))
    	response.setContentType("image/gif");
    else if (postfix.equalsIgnoreCase("bmp"))
    	response.setContentType("image/bmp");
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    String folder = this.getServletConfig().getServletContext().getInitParameter("sampleImageFolder");
    
    if (folder == null) {
    	response.reset();
    	return;
    }
    
    try {
    	try {
        	bis = new BufferedInputStream(new FileInputStream(folder + "/" + path));
        } catch (IOException e) {
        	bis = new BufferedInputStream(new FileInputStream(folder + "/" + "default.jpg"));
        }
        
        bos = new BufferedOutputStream(response.getOutputStream());

        byte[] buff = new byte[2048];
        int bytesRead;

        while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
            bos.write(buff, 0, bytesRead);
        }

    } catch(final IOException e) {
        //e.printStackTrace();
    } finally {
        if (bis != null)
            bis.close();
        if (bos != null)
            bos.close();
    }
    
    return;
    
// 注意：下面的尖括号和百分号后千万不能有回车等任何内容！否则会出现OutputStream冲突的错误！！！
%>